﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Dotnet.FormExtensions
{
    public static partial class Ext
    {
        public static string GetCurrentCellString(this DataGridViewCell cell,ref string cellName)
        {
            if (cell == null)
                return "";
            cellName = cell.OwningColumn.Name.Trim();
            string cellValue = "";
            if (cell.ValueType.Name.Trim().Equals("Byte[]")==true)
            {
                cellValue = cell.Value == DBNull.Value ? "" : Encoding.UTF8.GetString((byte[])cell.Value);
                return cellValue;
            }
            cellValue = cell.Value == DBNull.Value ? "" : cell.Value.ToString();
            return cellValue;
        }
        public static string GetCurrentCellString(this DataGridViewCell cell)
        {
            string name = "";
            return GetCurrentCellString(cell, ref name);
        }
    }
}
